package com.meitianhui.convenitenbuy.module.home.ui;

import android.content.Intent;
import android.graphics.Color;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.jakewharton.rxbinding.view.RxView;
import com.meitianhui.convenitenbuy.App;
import com.meitianhui.convenitenbuy.Constants;
import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.base.BaseFragment;
import com.meitianhui.convenitenbuy.config.InfoProvider;
import com.meitianhui.convenitenbuy.main.model.bean.AppToken;
import com.meitianhui.convenitenbuy.main.model.bean.EventBean;
import com.meitianhui.convenitenbuy.main.model.bean.SignInfo;
import com.meitianhui.convenitenbuy.main.model.bean.UserToken;
import com.meitianhui.convenitenbuy.main.model.event.ExitEvent;
import com.meitianhui.convenitenbuy.module.home.adapter.HomeAdapter;
import com.meitianhui.convenitenbuy.module.home.contract.HomeContract;
import com.meitianhui.convenitenbuy.module.home.di.DaggerHomeComponent;
import com.meitianhui.convenitenbuy.module.home.di.HomeModule;
import com.meitianhui.convenitenbuy.module.home.model.bean.AreaCode;
import com.meitianhui.convenitenbuy.module.home.model.bean.BannerBean;
import com.meitianhui.convenitenbuy.module.home.model.bean.HomeGoodsInfo;
import com.meitianhui.convenitenbuy.module.home.model.bean.HomeMultiItemType;
import com.meitianhui.convenitenbuy.module.home.model.bean.RecommendGoods;
import com.meitianhui.convenitenbuy.module.home.model.bean.ZeroBuyImage;
import com.meitianhui.convenitenbuy.module.home.presenter.HomePresenter;
import com.meitianhui.convenitenbuy.module.home.ui.activity.HomeScanCodeActivity;
import com.meitianhui.convenitenbuy.module.home.ui.activity.HomeSearchActivity;
import com.meitianhui.convenitenbuy.module.home.ui.activity.ZeroBuyActivity;
import com.meitianhui.convenitenbuy.module.home.ui.activity.web.AdWebViewActivity;
import com.meitianhui.convenitenbuy.module.home.ui.activity.web.BrandWebViewActivity;
import com.meitianhui.convenitenbuy.module.home.ui.activity.web.BusinessWebViewActivity;
import com.meitianhui.convenitenbuy.module.home.ui.activity.web.EdinburghWebViewActivity;
import com.meitianhui.convenitenbuy.module.home.ui.activity.web.MemberRulesWebViewActivity;
import com.meitianhui.convenitenbuy.module.mine.model.LogOutBean;
import com.meitianhui.convenitenbuy.util.JumpUtil;
import com.meitianhui.convenitenbuy.util.LocationService;
import com.meitianhui.convenitenbuy.util.PreferenceUtils;
import com.meitianhui.convenitenbuy.util.RxBus;
import com.meitianhui.convenitenbuy.util.RxUtils;
import com.meitianhui.convenitenbuy.util.SystemUtils;
import com.meitianhui.convenitenbuy.util.TipUtils;
import com.meitianhui.convenitenbuy.widget.dialog.AdDialog;
import com.meitianhui.convenitenbuy.widget.dialog.LoadingDialog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

import static com.meitianhui.convenitenbuy.Constants.EXIT_HYPHENATE_EVENT;
import static com.meitianhui.convenitenbuy.module.home.model.bean.HomeMultiItemType.ITEM_BANNER;
import static com.meitianhui.convenitenbuy.module.home.model.bean.HomeMultiItemType.ITEM_GOOD_INFO;
import static com.meitianhui.convenitenbuy.module.home.model.bean.HomeMultiItemType.ITEM_GOOD_TYPE;
import static com.meitianhui.convenitenbuy.module.home.model.bean.HomeMultiItemType.ITEM_MEMBER_FUNCTION;
import static com.meitianhui.convenitenbuy.module.home.model.bean.HomeMultiItemType.ITEM_PULL_DATA;
import static com.meitianhui.convenitenbuy.module.home.model.bean.HomeMultiItemType.ITEM_RECOMMEND_GOODS;
import static com.meitianhui.convenitenbuy.module.home.model.bean.HomeMultiItemType.ITEM_ZERO_BUY;

public class HomeFragment extends BaseFragment
        implements HomeContract.View, SwipeRefreshLayout.OnRefreshListener {

    public static final String Tag = HomeFragment.class.getSimpleName();
    private RecyclerView mRvHome;
    private SwipeRefreshLayout mSwipeHome;
    private ImageView mIvTop, mIvWish;
    private ImageView mIvPic;
    // 大的类目
    int mRlTypeIds[] = {
            R.id.rl_type_edinburgh,
            R.id.rl_type_will,
            R.id.rl_type_fight_group,
            R.id.rl_type_brand,
            R.id.rl_type_small_daily_home,
            R.id.rl_type_small_electrical,
            R.id.rl_type_small_baby_product,
            R.id.rl_type_small_clothes,
            R.id.rl_type_small_fresh_food};
    int mTvTypeIds[] = {
            R.id.tv_type_edinburgh,
            R.id.tv_type_will,
            R.id.tv_type_fight_group,
            R.id.tv_type_brand};
    TextView mTvType[] = new TextView[4];

    int mIvTypeIds[] = {
            R.id.iv_type_edinburgh,
            R.id.iv_type_will,
            R.id.iv_type_fight_group,
            R.id.iv_type_brand};
    ImageView mIvType[] = new ImageView[4];
    // 小的类目
    private LinearLayout mlLSmallTypeBg;
    int mTvTypeSmallIds[] = {
            R.id.tv_type_small_daily_home,
            R.id.tv_type_small_electrical,
            R.id.tv_type_small_baby_product,
            R.id.tv_type_small_clothes,
            R.id.tv_type_small_fresh_food};
    TextView mTvTypeSmall[] = new TextView[5];

    int mIvTypeSmallIds[] = {
            R.id.iv_type_small_daily_home,
            R.id.iv_type_small_electrical,
            R.id.iv_type_small_baby_product,
            R.id.iv_type_small_clothes,
            R.id.iv_type_small_fresh_food};
    ImageView mIvTypeSmall[] = new ImageView[5];

    private int mTypeChooseBg = R.mipmap.icon_home_edinburgh;
    private String mTypeChooseColor = "#ea5d08";
    private String mTypeColor = "#c7693b";
    private LinearLayout mLlTypeChoose;  //类型选择
    private HomeAdapter mAdapter;
    private LinearLayoutManager mLinearManager;
    private List<HomeMultiItemType> multiItemTypes = new ArrayList<>();
    private int mPageIndex = 1;
    private int mPageSize = 15;
    private boolean mIsFirst = true;
    private int lastVisibleItem;
    public static String mAreaCode = "";   //拼团领需要获取位置信息
    private String mServer = "psGoods.consumer.freeGetGoodsListPageFind";   //默认淘淘领信息
    public static int mGoodInfoType = 0;    //默认请求类型淘淘领
    public static int mGoodInfoSmallType = 5;  //默认不选中
    private boolean mLoadMore = false;    //数据量是否足够来区别是否可以去上啦加载更多
    private String mLabel = "";
    private List<HomeGoodsInfo.Convient> mGoodConvient = new ArrayList<>();
    private HashMap<String, String> mUrlMap = new HashMap<>();
    private LocationService locationService;
    private LoadingDialog mDialog;
    private AdDialog mAdDialog;

    private int isRefresh = 0;

    @Inject
    HomePresenter presenter;
    private View mViewTypeTitleBar, mHomeViewType;

    @Override
    protected int getLayout() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView(LayoutInflater inflater) {
        super.initView(inflater);
        DaggerHomeComponent.builder()
                .appComponent(App.getInstance().getAppComponent())
                .homeModule(new HomeModule(this))
                .build()
                .inject(this);
        initView();
        registerPush();
        mRvHome.setOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE
                        && lastVisibleItem + 1 == mAdapter.getItemCount()) {
                    if (mLoadMore) {
                        mPageIndex++;
                        presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, mAreaCode);
                    }
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                lastVisibleItem = mLinearManager.findLastVisibleItemPosition();
                int position = mLinearManager.findFirstVisibleItemPosition();
                if (position >= 4) {    //滑动到第三种类型的时候判断类型的可见不可见
                    if (mLlTypeChoose.getVisibility() == View.GONE) {
                        mLlTypeChoose.setVisibility(View.VISIBLE);
                        mViewTypeTitleBar.setVisibility(View.VISIBLE);
                    }
                    mIvTop.setVisibility(View.VISIBLE);
                } else if (mLlTypeChoose.getVisibility() == View.VISIBLE) {
                    mLlTypeChoose.setVisibility(View.GONE);
                    mViewTypeTitleBar.setVisibility(View.GONE);
                    mIvTop.setVisibility(View.GONE);
                }

                if (position > 0) {
                    if (mGoodInfoType == 1) {
                        mIvWish.setVisibility(View.GONE);
                    } else {
                        mIvWish.setVisibility(View.VISIBLE);
                    }
                } else {
                    mIvWish.setVisibility(View.GONE);
                }

                if (isRefresh == 1) {
                    mHomeViewType.setVisibility(View.VISIBLE);
                    isRefresh = 0;
                }else{
                    mHomeViewType.setVisibility(View.GONE);
                }
            }
        });
    }

    private void initView() {
        //setTranslucentStatus(R.color.text_color_normal);
        mSwipeHome = (SwipeRefreshLayout) getViewById(R.id.swipe_home);
        mSwipeHome.setOnRefreshListener(this);
        mIvTop = (ImageView) getViewById(R.id.iv_top);
        RxUtils.bindEvents(mIvTop, this);
        mIvWish = (ImageView) getViewById(R.id.iv_wish);
        RxUtils.bindEvents(mIvWish, this);
        mLlTypeChoose = (LinearLayout) getViewById(R.id.ll_type_choose);
        mViewTypeTitleBar = getViewById(R.id.view_type_titlebar);
        int systemBarHeight = SystemUtils.getSystemBarHeight(getActivity());
        mViewTypeTitleBar.getLayoutParams().height = systemBarHeight
                + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, 0, App.getInstance().getResources().getDisplayMetrics());

        mHomeViewType = getViewById(R.id.view_home_type);
        mHomeViewType.getLayoutParams().height = systemBarHeight
                + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, 0, App.getInstance().getResources().getDisplayMetrics());

        mRvHome = (RecyclerView) getViewById(R.id.rv_home);
        mLinearManager = new LinearLayoutManager(getActivity());
        mLinearManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRvHome.setLayoutManager(mLinearManager);
        mlLSmallTypeBg = (LinearLayout) getViewById(R.id.ll_small_type_bg);
        //绑定事件
        //大类
        for (int i = 0; i < mRlTypeIds.length; i++) {
            RxUtils.bindEvents(getViewById(mRlTypeIds[i]), this);
        }
        for (int i = 0; i < mTvTypeIds.length; i++) {
            mTvType[i] = (TextView) getViewById(mTvTypeIds[i]);
        }
        for (int i = 0; i < mIvTypeIds.length; i++) {
            mIvType[i] = (ImageView) getViewById(mIvTypeIds[i]);
        }
        //小类
        for (int i = 0; i < mTvTypeSmallIds.length; i++) {
            mTvTypeSmall[i] = (TextView) getViewById(mTvTypeSmallIds[i]);
        }
        for (int i = 0; i < mIvTypeSmallIds.length; i++) {
            mIvTypeSmall[i] = (ImageView) getViewById(mIvTypeSmallIds[i]);
        }
        initRecyclerView();
        locationService = new LocationService(App.getInstance());
        locationService.registerListener(mListener);
        locationService.start();
        mAreaCode = PreferenceUtils.getString(getActivity(), Constants.AREA_CODE, "");
//        if (InfoProvider.getUserToken(getActivity()) != null) {
//            presenter.getAreaCode("114.032911", "22.533894", InfoProvider.getUserToken(getActivity()).getMember_id());
//            PreferenceUtils.putString(getActivity(), Constants.LONGITUDE, "114.032911");
//            PreferenceUtils.putString(getActivity(), Constants.LATITUDE, "22.533894");
//        }
        if (TextUtils.isEmpty(InfoProvider.getAppToken(getActivity()))) {
            presenter.getAppToken();
        } else {
            presenter.getBanner();
        }
    }

    private void registerPush() {
        Disposable disposable = RxBus.get().toFlowable(EventBean.class)
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<EventBean>() {
                    @Override
                    public void accept(EventBean bean) throws Exception {
                        if (bean != null) {
                            if (bean.type == Constants.EVENT_TYPE_LOGIN_SUCCESS) {
                                if (TextUtils.isEmpty(InfoProvider.getAppToken(getActivity()))) {
                                    presenter.getAppToken();
                                } else {
                                    presenter.getBanner();
                                }
                            }
                        }
                    }
                });
        Disposable disposable1 = RxBus.get().toFlowable(LogOutBean.class).subscribe(new Consumer<LogOutBean>() {
            @Override
            public void accept(LogOutBean logOutBean) throws Exception {
                if (logOutBean.logOut.equals("logout")) {
                    if (TextUtils.isEmpty(InfoProvider.getAppToken(getActivity()))) {
                        presenter.getAppToken();
                    } else {
                        presenter.getBanner();
                    }
                }
            }
        });
        Disposable disposable2 = RxBus.get().toFlowable(ExitEvent.class).subscribe(new Consumer<ExitEvent>() {
            @Override
            public void accept(ExitEvent exitEvent) throws Exception {
                if (exitEvent.mType == EXIT_HYPHENATE_EVENT) {
                    if (TextUtils.isEmpty(InfoProvider.getAppToken(getActivity()))) {
                        presenter.getAppToken();
                    } else {
                        presenter.getBanner();
                    }
                }
            }
        });
        mCompositeDisposable.add(disposable);
        mCompositeDisposable.add(disposable1);
        mCompositeDisposable.add(disposable2);
    }

    /**
     * 初始化列表
     */
    private void initRecyclerView() {
        BannerBean banner = new BannerBean();
        multiItemTypes.add(new HomeMultiItemType(ITEM_BANNER, banner));
        multiItemTypes.add(new HomeMultiItemType(ITEM_MEMBER_FUNCTION));
        RecommendGoods recommendGoods = new RecommendGoods();
        multiItemTypes.add(new HomeMultiItemType(ITEM_RECOMMEND_GOODS, recommendGoods));
        ZeroBuyImage zeroBuyImage = new ZeroBuyImage();
        multiItemTypes.add(new HomeMultiItemType(ITEM_ZERO_BUY, zeroBuyImage));
        multiItemTypes.add(new HomeMultiItemType(ITEM_GOOD_TYPE));
        multiItemTypes.add(new HomeMultiItemType(ITEM_GOOD_INFO, null, null, mGoodInfoType));
        multiItemTypes.add(new HomeMultiItemType(ITEM_PULL_DATA));
        mAdapter = new HomeAdapter(getActivity(), multiItemTypes, mGoodInfoType);
        mRvHome.setAdapter(mAdapter);
        adapterInterface();
    }


    /**
     * 适配器中接口方法回调
     */
    private void adapterInterface() {
        mAdapter.setOnHomeAdapterOnClickListener(new HomeAdapter.HomeAdapterOnClickListener() {
            //搜索
            @Override
            public void searchClick() {
                startActivity(new Intent(getActivity(), HomeSearchActivity.class));
            }

            //扫一扫
            @Override
            public void scanCodeClick() {
                if (!InfoProvider.getLoginStatus(getActivity())) {
                    JumpUtil.jumpToLoginActivity(0, getActivity(), 0, "");
                    return;
                }
                startActivity(new Intent(getActivity(), HomeScanCodeActivity.class));
            }

            @Override
            public void signInClick() {   //签到
                if (!InfoProvider.getLoginStatus(getActivity())) {
                    JumpUtil.jumpToLoginActivity(0, getActivity(), 0, "");
                    return;
                }
                presenter.signInToday();
            }

            @Override
            public void phoneChargeClick() {  //话费充值
                //暂时作为会过的提交订单调试的地方

                // Intent intentTest = new Intent(getActivity(), SubmitOrderActivity.class);
                // startActivity(intentTest);
                if (!InfoProvider.getLoginStatus(getActivity())) {
                    JumpUtil.jumpToLoginActivity(0, getActivity(), 0, "");
                    return;
                }
                Intent intent = new Intent(getActivity(), AdWebViewActivity.class);
                intent.putExtra("url", Constants.HOST + "h5/common/mobile-fee"
                        + "?member_id=" + InfoProvider.getUserToken(App.getInstance()).getMember_id()
                        + "&member_type_key=consumer");
                intent.putExtra("title", "话费充值");
                startActivity(intent);
            }

            @Override
            public void newStrategyClick() {   //新人攻略
                Intent intent = new Intent(getActivity(), AdWebViewActivity.class);
                //测试环境
                // intent.putExtra("url", Constants.HOST
                //        + "h5/c/tag?label=freshman&type=2&banner=https://oss-img.meitianhui.com/communityDocs/201706/4bcdba62a9004d6daeab6241cdb03a4f.jpg");
                //正式环境
                intent.putExtra("url", Constants.HOST
                        + "h5/c/tag2?label=freshman&version=new&type=2&banner=https://oss-img.meitianhui.com/test/communityDocs/201707/6d3b129d8e1e4ea187bee3e7db3bba9c.jpg");
                intent.putExtra("title", "新人攻略");
                startActivity(intent);
            }

            @Override
            public void memberRulesClick() {   //会员权益
                if (!InfoProvider.getLoginStatus(getActivity())) {
                    JumpUtil.jumpToLoginActivity(0, getActivity(), 0, "");
                    return;
                }
                String memberId = InfoProvider.getUserToken(getActivity()).getMember_id();
                String mobile = InfoProvider.getUserToken(getActivity()).getMobile();
                Intent intent = new Intent(getActivity(), MemberRulesWebViewActivity.class);
                intent.putExtra("url", Constants.HOST
                        + "h5/c/interests" + "?member_id=" + memberId + "&mobile=" + mobile);
                intent.putExtra("title", "会员权益");
                intent.putExtra("member_id", memberId);
                intent.putExtra("mobile", mobile);
                startActivity(intent);
            }

            @Override
            public void businessCooClick() {   //商家合作
                Intent intent = new Intent(getActivity(), BusinessWebViewActivity.class);
                intent.putExtra("url", Constants.HOST + "h5/c/businessPartner");
                intent.putExtra("title", "商家合作");
                startActivity(intent);
            }

            @Override
            public void bigTypeClick(int position) {
                mPageIndex = 1;
                mGoodInfoType = position;
                adapterClick();
                if (position == 0) {
                    mServer = "psGoods.consumer.freeGetGoodsListPageFind";
                } else if (position == 1) {
                    mServer = "psGoods.consumer.freeGetGoodsForHuiguoListPageFind";
                } else if (position == 2) {
                    //自营
                    mServer = "psGoods.consumer.freeGetGoodsForNewOwnListPageFind";
                } else if (position == 3) {
                    // 改为9块9包邮
                    mServer = "psGoods.consumer.less9PsGoodsListPageFindNewOwn";
                }

                mLabel = "";
                if (TextUtils.isEmpty(InfoProvider.getAppToken(getActivity()))) {
                    presenter.getAppToken();
                }
                if (position == 1 || position == 2) {
                    if (TextUtils.isEmpty(mAreaCode)) {
                        TipUtils.showToast(App.getInstance(), "获取定位失败", 2);
                        return;
                    }
                    if (mDialog == null) {
                        mDialog = new LoadingDialog(getActivity());
                    }
                    presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, "", mAreaCode);
                } else {
                    if (mDialog == null) {
                        mDialog = new LoadingDialog(getActivity());
                    }
                    presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, "", "");
                }
            }

            @Override
            public void smallTypeClick(int position) {
                mPageIndex = 1;
                mGoodInfoSmallType = position;
                tvSmallColor(mTvTypeSmall[position], mTypeColor, mTypeChooseColor, mIvTypeSmall[position]);
                if (mServer.equals("psGoods.consumer.tsGoodsListPageFind")) {
                    if (position == 0) {
                        mLabel = "百货";
                    } else if (position == 1) {
                        mLabel = "数码";
                    } else if (position == 2) {
                        mLabel = "母婴";
                    } else if (position == 3) {
                        mLabel = "服饰";
                    } else if (position == 4) {
                        mLabel = "美食";
                    }
                } else {

                    if (position == 0) {
                        mLabel = "日用家居";
                    } else if (position == 1) {
                        mLabel = "数码家电";
                    } else if (position == 2) {
                        mLabel = "母婴用品";
                    } else if (position == 3) {
                        mLabel = "服饰鞋包";
                    } else if (position == 4) {
                        mLabel = "食品生鲜";
                    }
                }
                if (TextUtils.isEmpty(InfoProvider.getAppToken(getActivity()))) {
                    presenter.getAppToken();
                }
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, mAreaCode);
            }

            // 限时抢购
            @Override
            public void limitTimeClick(String goodId, String picPath) {
                /*
                cate参数，cate值与分类对应如下：
                cate=recommend 推荐
                cate=new 上线
                cate=all 全部
                cate=forecast 预告
                cate=wish 心愿
                */
                // 调到预告板块
                Intent intent = new Intent(getActivity(), AdWebViewActivity.class);
                intent.putExtra("url", Constants.HOST + "h5/c/tag2?"
                        + "label=flashSale&version=zeroPurchase&banner=" + picPath);
                intent.putExtra("title", "限时抢购");
                intent.putExtra("type", "limit");
                getActivity().startActivity(intent);
            }

            // 明日预告
            @Override
            public void tomorrowClick(String goodId) {
                /*
                cate参数，cate值与分类对应如下：
                cate=recommend 推荐
                cate=new 上线
                cate=all 全部
                cate=forecast 预告
                cate=wish 心愿
                */
                // 调到预告板块
                Intent intent = new Intent(getActivity(), EdinburghWebViewActivity.class);
                String longitude = InfoProvider.getLongitude(getActivity());
                String latitude = InfoProvider.getLatitude(getActivity());
                if (InfoProvider.getLoginStatus(getActivity())) {
                    intent.putExtra("url", Constants.HOST + "h5/c/payback"
                            + "?longitude=" + longitude + "&latitude=" + latitude
                            + "&area_id=" + mAreaCode
                            + "&mi=" + InfoProvider.getUserToken(App.getInstance()).getMember_id()
                            + "&cate=forecast" + "&bind=1");
                } else {
                    intent.putExtra("url", Constants.HOST + "h5/c/payback"
                            + "?longitude=" + longitude + "&latitude=" + latitude
                            + "&area_id=" + mAreaCode + "&cate=forecast" + "&bind=1");
                }

                intent.putExtra("title", "明日预告");
                intent.putExtra("type", "payback");
                intent.putExtra("cate", "forecast");

                getActivity().startActivity(intent);
            }

            // 0元购
            @Override
            public void zeroBuyClick() {
                Intent intent = new Intent(getActivity(), ZeroBuyActivity.class);
                getActivity().startActivity(intent);
            }

            // 淘淘领 + 会过
            @Override
            public void edinburghClick(String goodId, String data_source, String pic_info_url) {
                // data_source是区分自营、会过、还是淘宝等的
                if ("huiguo".equals(data_source)) {
                    // 跳转到会过的商品详情界面
                    Intent intent = new Intent(getActivity(), EdinburghWebViewActivity.class);
                    if (InfoProvider.getLoginStatus(getActivity())) {
                        intent.putExtra("url", Constants.HOST
                                + "h5/c/payback/huiguo-detail?goods_id=" + goodId
                                + "&mi=" + InfoProvider.getUserToken(App.getInstance()).getMember_id()
                                + "&mobile=" + InfoProvider.getUserToken(App.getInstance()).getMobile());
                    } else {
                        intent.putExtra("url", Constants.HOST
                                + "h5/c/payback/huiguo-detail?goods_id=" + goodId);
                    }
                    intent.putExtra("title", "会过");
                    intent.putExtra("is_second", true);
                    intent.putExtra("goods_id", goodId);
                    intent.putExtra("pic_url", pic_info_url);
                    getActivity().startActivity(intent);

                } else if ("meitianhui".equals(data_source)) {
                    // 跳转到自营商品的界面
                    Intent intent = new Intent(getActivity(), EdinburghWebViewActivity.class);
                    if (InfoProvider.getLoginStatus(getActivity())) {
                        intent.putExtra("url", Constants.HOST
                                + "h5/c/payback/ziying-detail?goods_id=" + goodId
                                + "&mi=" + InfoProvider.getUserToken(App.getInstance()).getMember_id()
                                + "&mobile=" + InfoProvider.getUserToken(App.getInstance()).getMobile());
                    } else {
                        intent.putExtra("url", Constants.HOST
                                + "h5/c/payback/ziying-detail?goods_id=" + goodId);
                    }
                    intent.putExtra("title", "自营");
                    intent.putExtra("is_second", true);
                    intent.putExtra("goods_id", goodId);
                    intent.putExtra("pic_url", pic_info_url);
                    getActivity().startActivity(intent);

                } else {
                    Intent intent = new Intent(getActivity(), EdinburghWebViewActivity.class);
                    if (InfoProvider.getLoginStatus(getActivity())) {
                        intent.putExtra("url", Constants.HOST
                                + "h5/c/payback/detail?goods_id=" + goodId
                                + "&mi=" + InfoProvider.getUserToken(App.getInstance()).getMember_id()
                                + "&mobile=" + InfoProvider.getUserToken(App.getInstance()).getMobile()
                                + "&bind=1");
                    } else {
                        intent.putExtra("url", Constants.HOST
                                + "h5/c/payback/detail?goods_id=" + goodId + "&bind=1");
                    }
                    intent.putExtra("title", "淘淘领");
                    intent.putExtra("is_second", true);
                    intent.putExtra("goods_id", goodId);
                    intent.putExtra("pic_url", pic_info_url);
                    getActivity().startActivity(intent);
                }
            }

            // 自营
            @Override
            public void fightGroupClick(String goodId, String pic_info_url) {
                if (!InfoProvider.getLoginStatus(getActivity())) {
                    JumpUtil.jumpToLoginActivity(0, getActivity(), 0, "");
                    return;
                }
                String memberId = "";
                UserToken userToken = InfoProvider.getUserToken(getActivity());
                if (userToken != null) {
                    memberId = userToken.getMember_id();
                }
                if (TextUtils.isEmpty(memberId)) {
                    JumpUtil.jumpToLoginActivity(0, getActivity(), 0, "");
                    return;
                }

                // 跳转到自营商品的界面
                Intent intent = new Intent(getActivity(), EdinburghWebViewActivity.class);
                if (InfoProvider.getLoginStatus(getActivity())) {
                    intent.putExtra("url", Constants.HOST
                            + "h5/c/payback/ziying-detail?goods_id=" + goodId
                            + "&mi=" + InfoProvider.getUserToken(App.getInstance()).getMember_id()
                            + "&mobile=" + InfoProvider.getUserToken(App.getInstance()).getMobile());
                } else {
                    intent.putExtra("url", Constants.HOST
                            + "h5/c/payback/ziying-detail?goods_id=" + goodId);
                }
                intent.putExtra("title", "自营");
                intent.putExtra("is_second", true);
                intent.putExtra("goods_id", goodId);
                intent.putExtra("pic_url", pic_info_url);
                getActivity().startActivity(intent);

                // 将拼团领的地方改成自营
                /* String longitude = InfoProvider.getLongitude(getActivity());
                String latitude = InfoProvider.getLatitude(getActivity());
                Intent intent = new Intent(getActivity(), FightGroupWebViewActivity.class);
                intent.putExtra("url", Constants.HOST + "h5/c/hpt/detail"
                        + "?member_id=" + memberId + "&goods_id=" + goodId + "&longitude="
                        + longitude + "&latitude=" + latitude + "&v=" + SystemUtils.getVersionName(getActivity()));
                intent.putExtra("title", "商品详情");
                intent.putExtra("type", "group-purchase");
                intent.putExtra("is_second", true);
                startActivity(intent); */
            }

            // 品牌领的条目点击
            @Override
            public void brandClick(String goodId) {
                Intent intent = new Intent(getActivity(), BrandWebViewActivity.class);
                intent.putExtra("url", Constants.HOST + "h5/c/gold-exchange/list"
                        + "?brand=" + goodId + "&area_id=" + mAreaCode);
                intent.putExtra("title", "品牌领");
                intent.putExtra("is_second", true);
                startActivity(intent);
            }

        });
    }

    @Override
    public void call(View v) {
        switch (v.getId()) {
            case R.id.rl_type_edinburgh:    //淘淘领
                if (mDialog == null) {
                    mDialog = new LoadingDialog(getActivity());
                }
                mServer = "psGoods.consumer.freeGetGoodsListPageFind";
                mGoodInfoType = 0;
                mLabel = "";
                tvTypeColor(mTvType[0], mIvType[0], R.mipmap.icon_home_edinburgh_choose, mlLSmallTypeBg, R.color.homeEdinburghItem);
                tvTypeSmallColor(mTvTypeSmall[0], R.color.homeEdinburgh, R.color.homeEdinburghChoose, mIvTypeSmall[0]);
                rememberColor(R.mipmap.icon_home_edinburgh, "#c7693b", "#ea5d08");
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, "");
                break;
            case R.id.rl_type_will:   //会过
                mLabel = "";
                if (mDialog == null) {
                    mDialog = new LoadingDialog(getActivity());
                }
                mServer = "psGoods.consumer.freeGetGoodsForHuiguoListPageFind";
                mGoodInfoType = 1;
                tvTypeColor(mTvType[1], mIvType[1], R.mipmap.icon_home_will_choose, mlLSmallTypeBg, R.color.homeWillItem);
                tvTypeSmallColor(mTvTypeSmall[0], R.color.homeWill, R.color.homeWillChoose, mIvTypeSmall[0]);
                rememberColor(R.mipmap.icon_home_will, "#666666", "#333333");
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, "");
                break;
            case R.id.rl_type_fight_group:  //拼团领
                if (TextUtils.isEmpty(mAreaCode)) {
                    TipUtils.showToast(App.getInstance(), "获取定位失败", 2);
                    return;
                }
                mLabel = "";
                if (mDialog == null) {
                    mDialog = new LoadingDialog(getActivity());
                }
                mServer = "psGoods.consumer.freeGetGoodsForNewOwnListPageFind";
                mGoodInfoType = 2;
                tvTypeColor(mTvType[2], mIvType[2], R.mipmap.icon_home_fight_group_choose, mlLSmallTypeBg, R.color.homeFightGroupItem);
                tvTypeSmallColor(mTvTypeSmall[0], R.color.homeFightGroup, R.color.homeFightGroupChoose, mIvTypeSmall[0]);
                rememberColor(R.mipmap.icon_home_fight_group_circle, "#aa8a00", "#c8a200");
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, mAreaCode);
                break;
            case R.id.rl_type_brand:   // 品牌领 改为9块9包邮
                if (TextUtils.isEmpty(mAreaCode)) {
                    TipUtils.showToast(App.getInstance(), "获取定位失败", 2);
                    return;
                }
                mLabel = "";
                if (mDialog == null) {
                    mDialog = new LoadingDialog(getActivity());
                }
                mServer = "psGoods.consumer.less9PsGoodsListPageFindNewOwn";
                mGoodInfoType = 3;
                tvTypeColor(mTvType[3], mIvType[3], R.mipmap.icon_home_brand_choose, mlLSmallTypeBg, R.color.homeBrandItem);
                tvTypeSmallColor(mTvTypeSmall[0], R.color.homeBrand, R.color.homeBrandChoose, mIvTypeSmall[0]);
                // mlLSmallTypeBg.setVisibility(View.GONE);
                rememberColor(R.mipmap.icon_home_brand, "#a764e6", "#8c54c1");
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, mAreaCode);
                break;
            case R.id.rl_type_new_product:   //新品领
                mLabel = "";
                if (mDialog == null) {
                    mDialog = new LoadingDialog(getActivity());
                }
                mServer = "psGoods.consumer.freeGetGoodsNewestListPageFind";
                mGoodInfoType = 3;
                tvTypeColor(mTvType[3], mIvType[3], R.mipmap.icon_home_new_product_choose, mlLSmallTypeBg, R.color.homeNewProductItem);
                tvTypeSmallColor(mTvTypeSmall[0], R.color.homeNewProduct, R.color.homeNewProductChoose, mIvTypeSmall[0]);
                rememberColor(R.mipmap.icon_home_new_product, "#3da050", "#227d3f");
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, "");
                break;
            case R.id.rl_type_small_daily_home:  //日用家剧
                mGoodInfoSmallType = 0;
                tvSmallColor(mTvTypeSmall[0], mTypeColor, mTypeChooseColor, mIvTypeSmall[0]);
                if (mServer.equals("psGoods.consumer.tsGoodsListPageFind")) {
                    mLabel = "百货";
                } else {
                    mLabel = "日用家居";
                }
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, mAreaCode);
                break;
            case R.id.rl_type_small_electrical:  //数码家电
                mGoodInfoSmallType = 1;
                tvSmallColor(mTvTypeSmall[1], mTypeColor, mTypeChooseColor, mIvTypeSmall[1]);
                if (mServer.equals("psGoods.consumer.tsGoodsListPageFind")) {
                    mLabel = "数码";
                } else {
                    mLabel = "数码家电";
                }
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, mAreaCode);
                break;
            case R.id.rl_type_small_baby_product: //母婴产品
                mGoodInfoSmallType = 2;
                tvSmallColor(mTvTypeSmall[2], mTypeColor, mTypeChooseColor, mIvTypeSmall[2]);
                if (mServer.equals("psGoods.consumer.tsGoodsListPageFind")) {
                    mLabel = "母婴";
                } else {
                    mLabel = "母婴用品";
                }
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, mAreaCode);
                break;
            case R.id.rl_type_small_clothes:   //服饰鞋具
                mGoodInfoSmallType = 3;
                tvSmallColor(mTvTypeSmall[3], mTypeColor, mTypeChooseColor, mIvTypeSmall[3]);
                if (mServer.equals("psGoods.consumer.tsGoodsListPageFind")) {
                    mLabel = "服饰";
                } else {
                    mLabel = "服饰鞋包";
                }
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, mAreaCode);
                break;
            case R.id.rl_type_small_fresh_food:  //食品生鲜
                mGoodInfoSmallType = 4;
                tvSmallColor(mTvTypeSmall[4], mTypeColor, mTypeChooseColor, mIvTypeSmall[4]);
                if (mServer.equals("psGoods.consumer.tsGoodsListPageFind")) {
                    mLabel = "美食";
                } else {
                    mLabel = "食品生鲜";
                }
                presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, mAreaCode);
                break;

            case R.id.iv_top:    //走到顶部
                ((LinearLayoutManager) mRvHome.getLayoutManager())
                        .scrollToPositionWithOffset(4, mViewTypeTitleBar.getHeight());
                mHomeViewType.setVisibility(View.VISIBLE);
                isRefresh = 1;
                mIvTop.setVisibility(View.GONE);
                break;

            case R.id.iv_wish:   //心愿单
                if (!InfoProvider.getLoginStatus(getActivity())) {
                    JumpUtil.jumpToLoginActivity(0, getActivity(), 0, "");
                    return;
                }

                String longitude = InfoProvider.getLongitude(getActivity());
                String latitude = InfoProvider.getLatitude(getActivity());
                Intent intent = new Intent(getActivity(), EdinburghWebViewActivity.class);
                intent.putExtra("url", Constants.HOST + "h5/c/payback"
                        + "?longitude=" + longitude + "&latitude=" + latitude
                        + "&area_id=" + mAreaCode
                        + "&mi=" + InfoProvider.getUserToken(App.getInstance()).getMember_id()
                        + "&cate=wish" + "&bind=1");
                intent.putExtra("title", "我的收藏");
                intent.putExtra("type", "payback");
                intent.putExtra("cate", "wish");
                getActivity().startActivity(intent);

                /*
                String longitude = InfoProvider.getLongitude(getActivity());
                String latitude = InfoProvider.getLatitude(getActivity());
                if (mGoodInfoType == 0 || mGoodInfoType == 3) {
                    // 淘淘领心愿
                    Intent intent = new Intent(getActivity(), EdinburghWebViewActivity.class);
                    intent.putExtra("url", Constants.HOST + "h5/c/payback"
                            + "?longitude=" + longitude + "&latitude=" + latitude + "&area_id=" + mAreaCode
                            + "&mi=" + InfoProvider.getUserToken(App.getInstance()).getMember_id() + "&cate=wish" + "&bind=1");
                    intent.putExtra("title", "淘淘领");
                    intent.putExtra("type", "payback");
                    intent.putExtra("cate", "wish");
                    getActivity().startActivity(intent);
                } else if (mGoodInfoType == 1) {
                    // 自营领心愿
                    Intent intent = new Intent(getActivity(), FightGroupWebViewActivity.class);
                    intent.putExtra("url", Constants.HOST + "h5/c/hpt/collect"
                            + "?member_id=" + InfoProvider.getUserToken(App.getInstance()).getMember_id() + "&longitude="
                            + longitude + "&latitude=" + latitude + "&v=1");
                    intent.putExtra("title", "我的收藏");
                    intent.putExtra("type", "group-purchase");
                    intent.putExtra("is_second", true);
                    startActivity(intent);
                }
                */
                break;
            case R.id.ll_ad:
                RxView.visibility(getViewById(R.id.ll_ad)).call(false);
                break;
        }

    }

    /**
     * 获取广告
     *
     * @param data
     */
    @Override
    public void getAdSuccess(BannerBean data) {
    }


    @Override
    public void getAppTokenSuccess(AppToken appToken) {
        PreferenceUtils.putString(getActivity(), Constants.APP_TOKEN_KEY, appToken.getApp_token());
        PreferenceUtils.putString(getActivity(), Constants.APP_SECURITY_CODE, appToken.getSecurity_code());
        presenter.getBanner();
    }

    /**
     * 签到成功
     *
     * @param data
     */
    @Override
    public void signInTodaySuccess(SignInfo data) {
        if (data != null) {
            mAdDialog = new AdDialog(getActivity(), 1, () -> {
            });
            mAdDialog.setImagePath(data.getPath_url());
            mAdDialog.setTextContext(data.getTitle());
            RxBus.get().post(new EventBean(Constants.EVENT_TYPE_REFRESH));
        }
    }

    /**
     * 刷新方法
     */
    @Override
    public void onRefresh() {
        mPageIndex = 1;
        mIsFirst = true;
        if (TextUtils.isEmpty(InfoProvider.getAppToken(getActivity()))) {
            presenter.getAppToken();
        } else {
            presenter.getBanner();
        }
    }


    @Override
    public void getBannerSuccess(BannerBean data) {
        mSwipeHome.setRefreshing(false);
        multiItemTypes.set(0, new HomeMultiItemType(ITEM_BANNER, data));
        mAdapter.notifyItemChanged(ITEM_BANNER);
        mAdapter.notifyItemChanged(ITEM_MEMBER_FUNCTION);
        // 开始请求 推荐商品。
        presenter.getRecommendGoods();
        // 开始请求 0元购图片。
        presenter.getZeroBuyImage();

        mAdapter = new HomeAdapter(getActivity(), multiItemTypes, mGoodInfoType);
        mRvHome.setAdapter(mAdapter);
        mRvHome.setFocusableInTouchMode(false);
        mRvHome.requestFocus();
    }

    @Override
    public void getRecommendGoodsSuccess(RecommendGoods data) {
        mSwipeHome.setRefreshing(false);
        multiItemTypes.set(2, new HomeMultiItemType(ITEM_RECOMMEND_GOODS, data));
        mAdapter.notifyItemChanged(ITEM_RECOMMEND_GOODS);
        //淘淘领        mAdapter.notifyItemChanged(ITEM_GOOD_TYPE);

        presenter.getGoodsInfo(mPageIndex + "", mPageSize + "", mServer, mLabel, mAreaCode);
    }

    @Override
    public void getZeroBuyImageSuccess(ZeroBuyImage data) {
        mSwipeHome.setRefreshing(false);
        multiItemTypes.set(3, new HomeMultiItemType(ITEM_ZERO_BUY, data));
        mAdapter.notifyItemChanged(ITEM_ZERO_BUY);
    }

    /**
     * 成功请求到商品信息数据
     *
     * @param data
     */
    @Override
    public void getGoodsInfoSuccess(HomeGoodsInfo data) {
        if (mDialog != null) {
            mDialog.stopProgressDialog();
            mDialog = null;
        }
        if (data == null || mPageIndex == 1) {
            mGoodConvient.clear();
            mUrlMap.clear();
        }
        if (data != null) {
            if (data.getDoc_url() != null) {
                mUrlMap.putAll(data.getDoc_url());
            }
            mGoodConvient.addAll(data.getList());
            if (mGoodConvient.size() < mPageSize) {
                mLoadMore = false;
                mAdapter.setNoMore();
            } else {
                if (data.getList().size() < mPageSize) {
                    mLoadMore = false;
                    mAdapter.setCanLoadMore(false);
                } else {
                    mLoadMore = true;
                    mAdapter.setCanLoadMore(true);
                }
            }
            if (mPageIndex == 1 && mGoodConvient.size() == 0) {
                mAdapter.setFailLoadMore();
            }
        }
        HomeMultiItemType homeMultiItemType = new HomeMultiItemType(ITEM_GOOD_INFO, mGoodConvient, mUrlMap, mGoodInfoType);
        if (multiItemTypes.size() > 5) {
            multiItemTypes.set(5, homeMultiItemType);
        } else {
            multiItemTypes.add(5, homeMultiItemType);
        }
        if (multiItemTypes.size() > 6) {
            multiItemTypes.set(6, new HomeMultiItemType(ITEM_PULL_DATA));
        } else {
            multiItemTypes.add(6, new HomeMultiItemType(ITEM_PULL_DATA));
        }
        if (mPageIndex == 1 && !mIsFirst) {
            //加了titlebar后recyclerView会被遮挡一部分
            mHomeViewType.setVisibility(View.VISIBLE);
            ((LinearLayoutManager) mRvHome.getLayoutManager()).scrollToPositionWithOffset(4, mViewTypeTitleBar.getHeight());
            isRefresh = 1;
            // ((LinearLayoutManager) mRvHome.getLayoutManager()).scrollToPositionWithOffset(3, PixelUtils.dip2px(0));

        }
        mIsFirst = false;
        mSwipeHome.setRefreshing(false);
        mAdapter.notifyDataSetChanged();
        adapterInterface();

    }

    /**
     * 获取商品数据失败
     *
     * @param code
     * @param msg
     */
    @Override
    public void getGoodsInfoFail(int code, String msg) {
        if (mDialog != null) {
            mDialog.stopProgressDialog();
            mDialog = null;
        }
        mLoadMore = false;
        mGoodConvient.clear();
        mUrlMap.clear();
        if (code == Constants.FAILED_No_NET) {
            mAdapter.setNoNetWork(false);
        } else {
            mAdapter.setFailLoadMore();
        }
        mAdapter.notifyDataSetChanged();
        TipUtils.showToast(App.getInstance(), msg);
    }

    /**
     * 通过经纬度成功查询到区域code
     *
     * @param data
     * @Override
     */
    public void getAreaCodeSuccess(AreaCode data) {
        mAreaCode = data.getAreaCode();
        mSwipeHome.setRefreshing(false);
        PreferenceUtils.putString(getActivity(), Constants.AREA_CODE, mAreaCode);
    }

    @Override
    public void onDialogDismiss(int code, String msg) {
        mSwipeHome.setRefreshing(false);
        mLoadMore = false;
        if (code == Constants.FAILED_No_NET) {
            mGoodConvient.clear();
            mUrlMap.clear();
            multiItemTypes.add(6, new HomeMultiItemType(ITEM_PULL_DATA));
            mAdapter.setNoNetWork(false);
            mAdapter.notifyDataSetChanged();
        }
    }

    /**
     * 点击大类颜色背景的改变
     *
     * @param tv   大类目文本
     * @param iv   类目下面图片是否选中
     * @param bg   文本的背景
     * @param ll   小类目LinearLayout
     * @param llBg 小类目LinearLayout背景
     */
    private void tvTypeColor(TextView tv, ImageView iv, int bg, LinearLayout ll, int llBg) {
        mPageIndex = 1;
        mGoodInfoSmallType = 5;
        for (int i = 0; i < mTvType.length; i++) {
            mTvType[i].setBackgroundResource(R.color.transparent);
            mTvType[i].setTextColor(getResources().getColor(R.color.text_color_normal));
            mIvType[i].setVisibility(View.INVISIBLE);
        }
        tv.setBackgroundResource(bg);
        tv.setTextColor(getResources().getColor(R.color.white));
        iv.setVisibility(View.VISIBLE);
        ll.setBackgroundResource(llBg);
        ll.setVisibility(View.VISIBLE);
    }

    /**
     * 点击大类记住颜色
     *
     * @param bg
     * @param color
     * @param chooseColor
     */
    private void rememberColor(int bg, String color, String chooseColor) {

        mTypeChooseBg = bg;
        mTypeColor = color;
        mTypeChooseColor = chooseColor;

    }

    /**
     * 点击大类改变小类颜色
     *
     * @param tv
     * @param color
     * @param chooseColor
     * @param iv
     */
    private void tvTypeSmallColor(TextView tv, int color, int chooseColor, ImageView iv) {
        for (int i = 0; i < mTvTypeSmall.length; i++) {
            mTvTypeSmall[i].setTextColor(getResources().getColor(color));
        }
        for (int i = 0; i < mIvTypeSmall.length; i++) {
            mIvTypeSmall[i].setBackgroundResource(R.color.transparent);
        }
//        tv.setTextColor(getResources().getColor(chooseColor));
//        iv.setBackgroundResource(mTypeChooseBg);
    }


    /**
     * 点击小类改变小类颜色
     *
     * @param iv
     */
    private void tvSmallColor(TextView tv, String normalColor, String chooseColor, ImageView iv) {
        mPageIndex = 1;
        for (int i = 0; i < mIvTypeSmall.length; i++) {
            mIvTypeSmall[i].setBackgroundResource(R.color.transparent);
            mTvTypeSmall[i].setTextColor(Color.parseColor(normalColor));
        }
        iv.setBackgroundResource(mTypeChooseBg);
        tv.setTextColor(Color.parseColor(chooseColor));
        if (mDialog == null) {
            mDialog = new LoadingDialog(getActivity());
        }
        if (mServer.equals("psGoods.consumer.freeGetGoodsListPageFind")) {   //淘淘领
            mServer = "psGoods.consumer.freeGetGoodsByLabelListPageFind";
        }
        if (mServer.equals("psGoods.consumer.freeGetGoodsForHuiguoListPageFind")) {   //会过
            mServer = "psGoods.consumer.freeGetGoodsForHuiguoByLabelListPageFind";
        }
        if (mServer.equals("psGoods.consumer.freeGetGoodsForNewOwnListPageFind")){//自营
            mServer = "psGoods.consumer.freeGetGoodsForNewOwnByLabelListPageFind";
        }
    }

    /**
     * adapter的点击
     */
    private void adapterClick() {
        mGoodInfoSmallType = 5;
        if (mGoodInfoType == 0) {
            tvTypeColor(mTvType[0], mIvType[0], R.mipmap.icon_home_edinburgh_choose, mlLSmallTypeBg, R.color.homeEdinburghItem);
            tvTypeSmallColor(mTvTypeSmall[0], R.color.homeEdinburgh, R.color.homeEdinburghChoose, mIvTypeSmall[0]);
            rememberColor(R.mipmap.icon_home_edinburgh, "#c7693b", "#ea5d08");
        }else if (mGoodInfoType == 1) {
            tvTypeColor(mTvType[1], mIvType[1], R.mipmap.icon_home_will_choose, mlLSmallTypeBg, R.color.homeWillItem);
            tvTypeSmallColor(mTvTypeSmall[0], R.color.homeWill, R.color.homeWillChoose, mIvTypeSmall[0]);
            rememberColor(R.mipmap.icon_home_will, "#666666", "#333333");
        } else if (mGoodInfoType == 2) {
            tvTypeColor(mTvType[2], mIvType[2], R.mipmap.icon_home_fight_group_choose, mlLSmallTypeBg, R.color.homeFightGroupItem);
            tvTypeSmallColor(mTvTypeSmall[0], R.color.homeFightGroup, R.color.homeFightGroupChoose, mIvTypeSmall[0]);
            rememberColor(R.mipmap.icon_home_fight_group_circle,  "#c8a200", "#aa8a00");
        } else if (mGoodInfoType == 3) {
            tvTypeColor(mTvType[3], mIvType[3], R.mipmap.icon_home_brand_choose, mlLSmallTypeBg, R.color.homeBrandItem);
            tvTypeSmallColor(mTvTypeSmall[0], R.color.homeBrand, R.color.homeBrandChoose, mIvTypeSmall[0]);
            rememberColor(R.mipmap.icon_home_brand, "#a764e6", "#8c54c1");
        }
    }

    @Override
    public void showError(String msg) {
    }

    private BDLocationListener mListener = new BDLocationListener() {
        @Override
        public void onReceiveLocation(final BDLocation location) {
            try {
                locationService.stop();
                if (null != location && location.getLocType() != BDLocation.TypeServerError
                        && !(location.getLatitude() + "").equals("4.9E-324") && !(location.getLatitude() + "").equals("4.9E-324")) {
                    Log.i("location", "经度：" + location.getLongitude());
                    Log.i("location", "纬度：" + location.getLatitude());
                    String city = location.getCity();
                    //保存经纬度
                    PreferenceUtils.putString(App.getInstance(), Constants.LONGITUDE, location.getLongitude() + "");
                    PreferenceUtils.putString(App.getInstance(), Constants.LATITUDE, location.getLatitude() + "");
                    PreferenceUtils.putString(App.getInstance(), Constants.CITY, location.getCity() + "");
                    PreferenceUtils.putString(App.getInstance(), Constants.DISTRICT, location.getDistrict() + "");

                    String memberId = "";
                    UserToken userToken = InfoProvider.getUserToken(App.getInstance());
                    if (userToken != null) {
                        memberId = userToken.getMember_id();
                    }
                    presenter.getAreaCode(location.getLatitude() + "", location.getLongitude() + "", memberId);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}
